﻿using IntelligentAgriculture.Contracts.Dto.Output;
using IntelligentAgriculture.Domain.Entity;
using IntelligentAgriculture.WebAPI.Application.Command.ParturitionCommand;
using IntelligentAgriculture.WebAPI.Application.Command.PregnancyCommand;
using IntelligentAgriculture.WebAPI.Application.CommandHandler.ParturitionCommandHandler;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace IntelligentAgriculture.WebAPI.Controllers
{
    /// <summary>
    /// 种母分娩
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ParturitionsController : ControllerBase
    {
        private readonly IMediator _mediator;
        private readonly ILogger<ParturitionsController> _logger;
        public ParturitionsController(IMediator mediator, ILogger<ParturitionsController> logger)
        {
            _mediator = mediator;
            _logger = logger;
        }
        /// <summary>
        /// 种母分娩列表
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Results<PageOutput<ParturitionOutput>>> GetParturitionAsync(ParturitionGetCommand command)
        {
            try
            {
                var result =await _mediator.Send(command);
                return Results<PageOutput<ParturitionOutput>>.DataResult(result);
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 种母分娩添加
        /// </summary>
        /// <param name="childbirths"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Results<int>> AddParturition(List<Childbirth> childbirths)
        {
            try
            {
                var result = new ParturitionAddCommand(childbirths);
                var command =await _mediator.Send(result);
                return Results<int>.DataResult(command);
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 种母分娩删除功能
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Results<int>> DeleParturition(ParturitionDeleteCommand command)
        {
            try
            {
                var result = await _mediator.Send(command);
                return Results<int>.DataResult(result);
            }
            catch (Exception)
            {

                throw;
            }

        }
    }
}
